package user

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method("POST")
        url("/api/users/searches")
        body("""
            {
                "usernameOrEmail":["zhang"]
            }
            """)
        headers {
            header('Content-Type', 'application/json;charset=UTF-8')
        }
//        bodyMatchers {
//            jsonPath('$.usernameOrEmail[*]', byEquality())
//        }
    }
    response {
        status(201)
        body("""
            [{
                "id":"1",
                "username":"zhang",
                "email":"zhang@qq.com",
                "mobilePhone":"12345678901",
                "createDate":"2018-08-08"
            },{
                "id":"2",
                "username":"li",
                "email":"li@qq.com",
                "mobilePhone":"12345678902",
                "createDate":"2018-08-08"
            }]
            """)
        bodyMatchers {
            jsonPath('$[*]', byType())
            jsonPath('$[*].id', byRegex(number()))
            jsonPath('$[*].username', byType())
            jsonPath('$[*].email', byRegex(email()))
            jsonPath('$[*].mobilePhone', byRegex(number()))
            jsonPath('$[*].createDate', byType())
        }
    }
}
